import AlertComponent from "./Alert.vue"

const Alert = {};

Alert.install =  (Vue) => {
  // 将文件转换成一个vue组件
  const AlertConstructor = Vue.extend(AlertComponent);
  // 实例化vue组件
  let instance = new AlertConstructor();
  // 创建一个div, 并把组件里面的element挂载到div上
  instance.$mount(document.createElement("div"));
  // 将创建的div(也就是组件)插入到document上
  document.body.appendChild(instance.$el);

  // 4. 添加实例方法
  Vue.prototype.$alert = (msg) => {
    // 逻辑...
    // 这种写法相当于就是props(但是又可以检测更新??????)
    instance.msg = msg;
    instance.isShow = true;
  }

  Vue.prototype.$confirm = (msg, success, cancel) => {
    // 逻辑...
    instance.type = "confirm"
    instance.msg = msg;
    instance.isShow = true;
    if (typeof success !== "undefined") {
      instance.success = success;
    }
    if (typeof cancel !== "undefined") {
      instance.cancel = cancel;
    }
  }
}

export default Alert;